import { getItem, setItem, TOKEN, newAxiosRequest } from '@hs-admin/utils'
import { message } from '@hs-admin/utils'

const commonConfig = {
  loginUrl: '/api/datashop/v3/auth/oauth/hs/login',
  refreshTokenUrl: {
    axiosConfig: {
      url: `${import.meta.env.VITE_DATA_SHOP_API_URL}/api/datashop/v3/auth/refresh-token`,
      method: 'post'
    },
    setToken: (res: { access_token: string; token_type: string }) => setItem(TOKEN, res.access_token)
  },
  getToken: () => getItem(TOKEN),
  handleMessage: message,
  loadingFunction: null
}

const { mainAxios: businessAxios } = newAxiosRequest({
  ...commonConfig,
  baseUrl: `${import.meta.env.VITE_BUSINESS_API_URL}`
})
const { mainAxios: projectAxios } = newAxiosRequest({
  ...commonConfig,
  baseUrl: `${import.meta.env.VITE_PROJECT_API_URL}`
})
const { mainAxios: datashopAxios } = newAxiosRequest({
  ...commonConfig,
  baseUrl: `${import.meta.env.VITE_DATA_SHOP_API_URL}`
})

export { businessAxios, projectAxios, datashopAxios }
